package com.sky.controller.admin;

import cn.hutool.core.util.ObjUtil;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @Content: 管理端-店铺相关接口
 * @Author: Asen
 * @Date: 2023/9/5 21:19
 */
@Api(tags = "店铺相关接口")
@Slf4j
@RestController("adminShopController")//避免和用户定义的接口在SpringBoot中bean名称冲突报错
@RequestMapping("/admin/shop")
public class ShopController {

    private final static String SHOP = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 设置店铺的营业状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("设置店铺的营业状态")
    public Result setStatus(@PathVariable Integer status){
        redisTemplate.opsForValue().set(SHOP,status);
        return Result.success();
    }

    @GetMapping("status")
    @ApiOperation("获取店铺的营业状态")
    public Result<Integer> getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(SHOP);
        if (ObjUtil.isNull(status)){
            status = 0;
            redisTemplate.opsForValue().set(SHOP,status);
        }
        return Result.success(status);
    }
}
